// JavaScript Document

//reset add new event form
function restForm(formName,textArea){
	//if there is a dojo text area, reset it;
	if(textArea != undefined){
		dijit.byId(textArea).setValue("");
	}

	//clear the rest of the form
	eval('document.'+ formName + '.reset();');

	//dijit.byId('website').setValue("http://");

}


function resetCatForm(){
	dijit.byId('eventCat').setDisplayedValue("Select Category:");
	dijit.byId('catName').setDisplayedValue("");
	dijit.byId('catDescription').setValue("");
	dijit.byId('add').setDisabled(true);
	dijit.byId('update').setDisabled(true);
	dijit.byId('delete').setDisabled(true);
	dijit.byId('resetCatForm').setDisabled(true);
}


function enableDisableButtons(){
	//initialize form buttons on manage event categories tab
	if(dijit.byId('eventCat').getValue() != "Select Category:"){
		dijit.byId('update').setDisabled(false);
		dijit.byId('delete').setDisabled(false);
		dijit.byId('resetCatForm').setDisabled(false);
		dijit.byId("add").setDisabled(true);
		retrieveCats();
	}
}

//retrieve category data for update or delete
function retrieveCats(){

		dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'getCat',catID:dijit.byId('eventCat').getValue()},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('catName').setDisplayedValue(response.catName);
		  dijit.byId('catDescription').setValue(response.catDesc);
		  dijit.byId("add").setDisabled(true);
		  }
		});

}

//used on the Manage Event Categories Tab > "Add New" button
function addNewCat(){

	dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'newCat',name:dijit.byId('catName').getDisplayedValue(),description:dijit.byId('catDescription').getValue()},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('systemMessages').setContent("You have successfully added the category: "+dijit.byId('catName').getDisplayedValue());
		  dijit.byId('systemMessages').toggle();
		  resetCatForm();
		  setTimeout('dijit.byId(\'systemMessages\').toggle(); dijit.byId(\'dropDownContentPane\').refresh();', 3000);
		  }
		});
}

//used on the Manage Event Categories Tab > "Update Category" button
function updateCat(){

	dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'updateCat',catID:dijit.byId('eventCat').getValue(),name:dijit.byId('catName').getDisplayedValue(),description:dijit.byId('catDescription').getValue()},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('systemMessages').setContent("You have successfully updated the category: "+dijit.byId('catName').getDisplayedValue());
		  dijit.byId('systemMessages').toggle();
		  resetCatForm();
		  setTimeout('dijit.byId(\'systemMessages\').toggle(); dijit.byId(\'dropDownContentPane\').refresh();', 3000);
		  }
		});
}



//used on the Manage Event Categories Tab > "Delete Category" button
function deleteCat(){

	dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'deleteCat',catID:dijit.byId('eventCat').getValue()},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('systemMessages').setContent("You have successfully deleted the category: "+dijit.byId('catName').getDisplayedValue());
		  dijit.byId('systemMessages').toggle();
		  resetCatForm();
		  setTimeout('dijit.byId(\'systemMessages\').toggle(); dijit.byId(\'dropDownContentPane\').refresh();', 3000);
		  }
		});
}


//#######################################################
//#######################################################
//#######################################################


function submitEvent(){

  	    dijit.byId('previewDialog').hide();

		dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  form: dojo.byId('add_new'),
		  content: {action:'newEvent',date1:dijit.byId('date1').getDisplayedValue(),time1:dijit.byId('time1').getDisplayedValue(),date2:'',time2:''/*date2:dijit.byId('date2').getDisplayedValue(),time2:dijit.byId('time2').getDisplayedValue()*/},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  if(response.success=='true'){
			  dijit.byId('systemMessages').setContent("You have successfully added the event: "+response.event);
			  dijit.byId('systemMessages').toggle();
			  restForm('add_new','description');
			  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  }else{
		  	  //if the above url fails it must be the end user submitting so try the admin/fetchData.php url
			  	  dojo.xhrPost({
					  url: "admin/includes/fetchData.php",
					  handleAs: "json-comment-filtered",
					  form: dojo.byId('add_new'),
					  content: {action:'newEvent',date1:dijit.byId('date1').getDisplayedValue(),time1:dijit.byId('time1').getDisplayedValue(),date2:'',time2:''/*date2:dijit.byId('date2').getDisplayedValue(),time2:dijit.byId('time2').getDisplayedValue()*/},
					  timeout: 5000,
					  handle: function(response, ioArgs){
					  if(response.success=='true'){
						  dijit.byId('systemMessages').setContent("You have successfully added the event: "+response.event);
						  dijit.byId('systemMessages').toggle();
						  restForm('add_new','description');
						  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
					  }else{
					  	  dijit.byId('systemMessages').setContent("There was an error adding this event: "+response.event);
						  dijit.byId('systemMessages').toggle();
						  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
					  }

					  }
					});

		  	  //################################################################
		  }

		  }
		});


}


function preview(){

	//VALIDATE FORM.  RETURN FALSE IF NOT VALID
	if(!dijit.byId('add_new').isValid() || dijit.byId('title').getDisplayedValue()=="" || dijit.byId('location').getDisplayedValue()=="" || dijit.byId('contact_name').getDisplayedValue()=="" || dijit.byId('contact_phone').getDisplayedValue()==""){
		  dijit.byId('systemMessages').setContent("Please enter all required fields!");
		  dijit.byId('systemMessages').toggle();
		  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  return false;
	}/*else if(dijit.byId('date2').getDisplayedValue() != "" || dijit.byId('time2').getDisplayedValue() != ""){

		//make sure end date IS after start date
		var milli_d1 = dijit.byId('date1').getValue().getTime();
		//if end date is empty go ahead and set diff = 0 meaning end date and start date are the same
		if(dijit.byId('date2').getDisplayedValue() == ""){
			var diff = 0;
		}else{
			var milli_d2 = dijit.byId('date2').getValue().getTime();
			var diff = milli_d2 - milli_d1;
		}

		if(diff < 0){
			//end date is before start date
			dijit.byId('systemMessages').setContent("Please make sure your end DATE is not before your start DATE!");
		  	dijit.byId('systemMessages').toggle();
		  	setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  	return false;
		}

		//WE NOW KNOW THAT THE END DATE IS VALID SO LETS MAKE SURE END TIME IS GOOD IF END DATE AND START DATE ARE THE SAME
		if(diff == 0){
			var milli_t1 = dijit.byId('time1').getValue().getTime();
			var milli_t2 = dijit.byId('time2').getValue().getTime();
			var diff_t = milli_t2 - milli_t1;
			if(diff_t <= 0){
				//end time is not after start date
				dijit.byId('systemMessages').setContent("Please make sure your end TIME is not before your start TIME!");
			  	dijit.byId('systemMessages').toggle();
			  	setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			  	return false;
			}

		}

	}*/else if(dijit.byId('contact_email').getDisplayedValue() != ""){

		//MAKE SURE WE HAVE A VALID EMAIL ADDRESS
		if(dijit.byId('contact_email').getDisplayedValue().indexOf(".") == -1 || dijit.byId('contact_email').getDisplayedValue().indexOf("@") == -1){
	 		dijit.byId('systemMessages').setContent("Please enter a valid email address!");
			dijit.byId('systemMessages').toggle();
		    setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			return(false);
		}

	}else if(dijit.byId('website').getDisplayedValue() != "http://" && dijit.byId('website').getDisplayedValue() != ""){

		//MAKE SURE WE HAVE A VALID URL
		if(dijit.byId('website').getDisplayedValue().indexOf(".") == -1){
	 		dijit.byId('systemMessages').setContent("Please enter a valid website address!");
			dijit.byId('systemMessages').toggle();
		    setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			return(false);
		}

	}


	//PASSED VALIDATION SO SHOW PREVIEW
		dijit.byId('previewDialog').show();
		dojo.byId('d_title').innerHTML=dijit.byId('title').getDisplayedValue();
		dojo.byId('d_date').innerHTML="&#8226; <b>Start:</b> "+dijit.byId('date1').getDisplayedValue() +" - "+ dijit.byId('time1').getDisplayedValue();
		//dojo.byId('d_endDate').innerHTML="&#8226; <b>End:</b> "+dijit.byId('date2').getDisplayedValue() +" - "+ dijit.byId('time2').getDisplayedValue();
		dojo.byId('d_descr').innerHTML="&#8226; <b>Description:</b> "+dijit.byId('description').getValue();
		dojo.byId('d_loc').innerHTML="&#8226; <b>Location:</b> "+dijit.byId('location').getDisplayedValue();
		dojo.byId('d_name').innerHTML="&#8226; <b>Contact Name:</b> "+dijit.byId('contact_name').getDisplayedValue();
		dojo.byId('d_phone').innerHTML="&#8226; <b>Contact Phone:</b> "+dijit.byId('contact_phone').getDisplayedValue();
		dojo.byId('d_email').innerHTML="&#8226; <b>Contact Email:</b> "+dijit.byId('contact_email').getDisplayedValue();
		dojo.byId('d_url').innerHTML="&#8226; <b>Website:</b> "+dijit.byId('website').getDisplayedValue();

}

//############# EVENT APPROVAL FUNCTIONS
function eventDelete(ID,title){
	dojo.byId('de_title').innerHTML=title;
	eventID=ID;
	dijit.byId('eventDeleteDialog').show();
}

function eventEdit(ID){
	//select Event info from DB

	dojo.xhrPost({
				  url: "includes/fetchData.php",
				  handleAs: "json-comment-filtered",
				  content: {action:'fetchEvent',ID:ID},
				  timeout: 5000,
				  handle: function(response, ioArgs){
					  if(response.success=='true'){
					  	//alert(response.title);
					  	dijit.byId('eventEditDialog').show();
					  	dijit.byId('e_title').setDisplayedValue(response.title.replace("&#039;","'"));
					  	dijit.byId('e_date1').setDisplayedValue(response.s_date);
					  	dijit.byId('e_time1').setDisplayedValue(response.s_time);
					  	//dijit.byId('e_date2').setDisplayedValue(response.e_date);
					  	//dijit.byId('e_time2').setDisplayedValue(response.e_time);
					  	if(dijit.byId('e_eventCatAdd')){
					  		dijit.byId('e_eventCatAdd').setValue(response.EVT_CAT);
					  	}
					  	dijit.byId('e_description').setValue(response.EVT_DSCR.replace("&#039;","'"));
					  	dijit.byId('e_location').setValue(response.EVT_LOC.replace("&#039;","'"));
					  	dijit.byId('e_contact_name').setValue(response.CON_NAME.replace("&#039;","'"));
					  	dijit.byId('e_contact_phone').setValue(response.CON_NUM);
					  	dijit.byId('e_contact_email').setValue(response.EMAIL);
					  	dijit.byId('e_website').setValue(response.URL);


					  	dojo.byId('e_header').innerHTML = response.title;
					  }
				  }
				});

}


//#############################
//validate event update form - sloppy spagetti code... sorry
//#############################
function validateEvntEdit(){

	//VALIDATE FORM.  RETURN FALSE IF NOT VALID
	if(dijit.byId('e_title').getDisplayedValue()=="" || dijit.byId('e_location').getDisplayedValue()=="" || dijit.byId('e_contact_name').getDisplayedValue()=="" || dijit.byId('e_contact_phone').getDisplayedValue()==""){
		  dijit.byId('systemMessages').setContent("Please enter all required fields!");
		  dijit.byId('systemMessages').toggle();
		  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  return false;
	}/*else if(dijit.byId('e_date2').getDisplayedValue() != "" || dijit.byId('e_time2').getDisplayedValue() != ""){

		//make sure end date IS after start date
		var milli_d1 = dijit.byId('e_date1').getValue().getTime();
		//if end date is empty go ahead and set diff = 0 meaning end date and start date are the same
		if(dijit.byId('e_date2').getDisplayedValue() == ""){
			var diff = 0;
		}else{
			var milli_d2 = dijit.byId('e_date2').getValue().getTime();
			var diff = milli_d2 - milli_d1;
		}

		if(diff < 0){
			//end date is before start date
			dijit.byId('systemMessages').setContent("Please make sure your end DATE is not before your start DATE!");
		  	dijit.byId('systemMessages').toggle();
		  	setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  	return false;
		}

		//WE NOW KNOW THAT THE END DATE IS VALID SO LETS MAKE SURE END TIME IS GOOD IF END DATE AND START DATE ARE THE SAME
		if(diff == 0){
			var milli_t1 = dijit.byId('e_time1').getValue().getTime();
			var milli_t2 = dijit.byId('e_time2').getValue().getTime();
			var diff_t = milli_t2 - milli_t1;
			if(diff_t <= 0){
				//end time is not after start date
				dijit.byId('systemMessages').setContent("Please make sure your end TIME is not before your start TIME!");
			  	dijit.byId('systemMessages').toggle();
			  	setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			  	return false;
			}

		}

	}*/else if(dijit.byId('e_contact_email').getDisplayedValue() != ""){

		//MAKE SURE WE HAVE A VALID EMAIL ADDRESS
		if(dijit.byId('e_contact_email').getDisplayedValue().indexOf(".") == -1 || dijit.byId('e_contact_email').getDisplayedValue().indexOf("@") == -1){
	 		dijit.byId('systemMessages').setContent("Please enter a valid email address!");
			dijit.byId('systemMessages').toggle();
		    setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			return(false);
		}

	}else if(dijit.byId('e_website').getDisplayedValue() != "http://" && dijit.byId('e_website').getDisplayedValue() != ""){

		//MAKE SURE WE HAVE A VALID URL
		if(dijit.byId('e_website').getDisplayedValue().indexOf(".") == -1){
	 		dijit.byId('systemMessages').setContent("Please enter a valid website address!");
			dijit.byId('systemMessages').toggle();
		    setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			return(false);
		}

	}

		//PASSED VALIDATION SO SUBMIT EVENT UPDATE
		dojo.xhrPost({
			  url: "includes/fetchData.php",
			  handleAs: "json-comment-filtered",
			  form: dojo.byId('edit'),
			  content: {action:'updateEvent',e_date1:dijit.byId('e_date1').getDisplayedValue(),e_time1:dijit.byId('e_time1').getDisplayedValue(),e_date2:'',e_time2:''/*e_date2:dijit.byId('e_date2').getDisplayedValue(),e_time2:dijit.byId('e_time2').getDisplayedValue()*/},
			  timeout: 5000,
			  handle: function(response, ioArgs){
			  if(response.success=='true'){
			  	  dijit.byId('eventEditDialog').hide();
				  dijit.byId('systemMessages').setContent("You have successfully updated the event: "+response.title);
				  dijit.byId('systemMessages').toggle();
				  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
	  			  dijit.byId('tab1').setHref('includes/event_item.php');
			  }

			  }
			});

}



//##############
//variable used by executeEventDeleteFrontSide()
//in admin.js to refresh appropriate tab
//##############

view='';

function executeEventDelete(){

if(view != ""){//front side delete
	subURL = 'admin/includes/fetchData.php';
	if(view == 'day'){
		tabContent = 'include/displays/day_view.php';
	}else if(view == 'month'){
		tabContent = 'include/displays/month_view.php';
	}
}else{//admin side delete
	subURL = 'includes/fetchData.php';
	tabContent = 'includes/event_item.php';
}


	dojo.xhrPost({
		  url: subURL,
		  handleAs: "json-comment-filtered",
		  content: {action:'deletEvent',ID:eventID},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('eventDeleteDialog').hide();
		  if(response.success=='true'){

		  	  	  if(view == ""){//
			  	  	  dijit.byId('tab1').setHref(tabContent);
					  dijit.byId('systemMessages').setContent("You have successfully deleted this event");
					  dijit.byId('systemMessages').toggle();
					  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
				  }else{
				  	fetchContent(view,'0');
				  }

		  }else{
		  		if(view == ""){//
			  	  dijit.byId('systemMessages').setContent("There was an error deleting this event");
				  dijit.byId('systemMessages').toggle();
				  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
			  	}
		  }

		  }
		});

}





function executeApproveEvent(eventID,Title){

	dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'approveEvent',ID:eventID},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('eventDeleteDialog').hide();
		  if(response.success=='true'){
		  	  dijit.byId('tab1').setHref('includes/event_item.php');
			  dijit.byId('systemMessages').setContent("You have successfully approved '"+Title+"'");
			  dijit.byId('systemMessages').toggle();
			  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  }else{
		  	  dijit.byId('systemMessages').setContent("There was an error approving '"+Title+"'");
			  dijit.byId('systemMessages').toggle();
			  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  }

		  }
		});
}



//############################################
//MEDIA NOTIFICATION SCRIPTS
//############################################


//--------------------------------------------------------------------------------
// function validateMediaForm()
// Validate form and return formValid variable which is true or false
// "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function validateMediaForm(){

	var formValid = false;

	//check to see if media name is valid
	if(dijit.byId('mediaName').getDisplayedValue() == ""){
		dijit.byId('systemMessages').setContent("Please enter a name for this media entity!");
		dijit.byId('mediaName').focus();
		dijit.byId('systemMessages').toggle();
	    setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		return(formValid);
	//check to see if media email is valid
	}else if(dijit.byId('mediaEmail').getDisplayedValue().indexOf(".") == -1 || dijit.byId('mediaEmail').getDisplayedValue().indexOf("@") == -1){
 		dijit.byId('systemMessages').setContent("Please enter a valid email address!");
		dijit.byId('mediaEmail').focus();
		dijit.byId('systemMessages').toggle();
	    setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		return(formValid);
	}else{
		formValid = true;
		return(formValid);
	}


}


//--------------------------------------------------------------------------------
// function addNewNotification()
// Submit the new Media Entitiy to the DB
// "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function addNewNotification(){

	//check to see if media name is valid
	if(validateMediaForm()){

		dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'addMediaNotif',name:dijit.byId('mediaName').getDisplayedValue(),email:dijit.byId('mediaEmail').getDisplayedValue()},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  if(response.success=='true'){
			  dijit.byId('systemMessages').setContent("You have successfully added '"+dijit.byId('mediaName').getDisplayedValue()+"'");
			  resetNotificationForm();
			  dijit.byId('systemMessages').toggle();
			  setTimeout('dijit.byId(\'systemMessages\').toggle();dijit.byId(\'dropDownMediaNotPane\').refresh();', 3000);
		  }else{
		  	  dijit.byId('systemMessages').setContent("There was an error adding '"+dijit.byId('mediaName').getDisplayedValue()+"'");
			  dijit.byId('systemMessages').toggle();
			  setTimeout('dijit.byId(\'systemMessages\').toggle();', 3000);
		  }

		  }
		});


	}
}


//--------------------------------------------------------------------------------
// function retrieveMediaEntities()
// Retrieve info for selected Media Entity to edit or delete
// "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function retrieveMediaEntities(){
	//initialize form buttons on manage event categories tab
	if(dijit.byId('mediaNot').getValue() != "Select Media Entity:"){
		dojo.xhrPost({
		  url: "includes/fetchData.php",
		  handleAs: "json-comment-filtered",
		  content: {action:'getMediaEntities',notID:dijit.byId('mediaNot').getValue()},
		  timeout: 5000,
		  handle: function(response, ioArgs){
		  dijit.byId('mediaName').setDisplayedValue(response.MediaName);
		  dijit.byId('mediaEmail').setDisplayedValue(response.email);
		  dijit.byId('updateNot').setDisabled(false);
		  dijit.byId('deleteNot').setDisabled(false);
		  dijit.byId('resetMediaNotForm').setDisabled(false);
		  dijit.byId("addNot").setDisabled(true);
		  }
		});




	}
}


//--------------------------------------------------------------------------------
// function updateMediaEntity()
// Updates the selelcted media entity on the
// "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function updateMediaEntity(){

		if(validateMediaForm()){
			dojo.xhrPost({
			  url: "includes/fetchData.php",
			  handleAs: "json-comment-filtered",
			  content: {action:'updateMediaEntity',notID:dijit.byId('mediaNot').getValue(),MediaName:dijit.byId('mediaName').getDisplayedValue(),email:dijit.byId('mediaEmail').getDisplayedValue()},
			  timeout: 5000,
			  handle: function(response, ioArgs){
			  dijit.byId('systemMessages').setContent("You have successfully updated the Media Entity: "+dijit.byId('mediaName').getDisplayedValue());
			  dijit.byId('systemMessages').toggle();
			  resetNotificationForm();
			  setTimeout('dijit.byId(\'systemMessages\').toggle(); dijit.byId(\'dropDownMediaNotPane\').refresh();', 3000);
			  }
			});

		}
}


//--------------------------------------------------------------------------------
// function resetNotificationForm()
// Reset the form to it's original state
// on the "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function resetNotificationForm(){
	dijit.byId('mediaName').setDisplayedValue("");
	dijit.byId('mediaEmail').setDisplayedValue("");
	dijit.byId('addNot').setDisabled(true);
	dijit.byId('updateNot').setDisabled(true);
	dijit.byId('deleteNot').setDisabled(true);
	dijit.byId('resetMediaNotForm').setDisabled(true);
	dijit.byId('dropDownMediaNotPane').refresh();
	dijit.byId('mediaName').focus();
}


//--------------------------------------------------------------------------------
// function enableAddBtn()
// Triggered from onChange handler from name field
// on the "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function enableAddBtn(){
	if(dijit.byId('mediaNot').getValue() == "Select Media Entity:"){
		dijit.byId('addNot').setDisabled(false);
	}
	dijit.byId('resetMediaNotForm').setDisabled(false);
}

//--------------------------------------------------------------------------------
// function deleteMediaEntity()
// Delete the selected Media Entity from the DB
// "Manage Media Notifications" tab
//--------------------------------------------------------------------------------
function deleteMediaEntity(){

		  dojo.xhrPost({
			  url: "includes/fetchData.php",
			  handleAs: "json-comment-filtered",
			  content: {action:'deleteMediaEntity',notID:dijit.byId('mediaNot').getValue()},
			  timeout: 5000,
			  handle: function(response, ioArgs){
			  dijit.byId('systemMessages').setContent("You have successfully deleted the Media Entity: "+dijit.byId('mediaName').getDisplayedValue());
			  dijit.byId('systemMessages').toggle();
			  resetNotificationForm();
			  setTimeout('dijit.byId(\'systemMessages\').toggle(); dijit.byId(\'dropDownMediaNotPane\').refresh();', 3000);
			  }
			});

}